package com.example.myapplication.cutvideo.handler;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;

import com.example.myapplication.R;
import com.example.myapplication.cutvideo.PlayActivity;


/**
 * <pre>
 *     author : yangzhi.ou
 *     e-mail : xxx@xx
 *     time   : 2019/05/26
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class LoadingDialog extends DialogFragment {
    private String loadingInfo;
    private TextView mTvLoading;

    private final static String TAG = "LoadingDialog";

    public LoadingDialog setLoadingInfo(String loadingInfo) {
        this.loadingInfo = loadingInfo;
        if (mTvLoading != null) {
            mTvLoading.setText(loadingInfo);
        }
        return this;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

        View view = inflater.inflate(R.layout.dialog_loading, container);
        mTvLoading = view.findViewById(R.id.tv_loading);
        if (loadingInfo != null) {
            mTvLoading.setText(loadingInfo);
        }
        return view;
    }

    public void show(FragmentManager manager) {
        super.show(manager, TAG);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Intent intent = new Intent(getContext(), PlayActivity.class);
        startActivity(intent);
    }
}
